package com.yunche.yunchebusiness.network

import okhttp3.Interceptor
import okhttp3.Response

/**
 * Create by Crcker on 2018/11/15 11:52
 * Email: Crcker@163.com
 */


class RequestInterceptor : Interceptor {


    override fun intercept(chain: Interceptor.Chain): Response { //偷天
        var oldRequest = chain.request()

        //拿到拥有以前的request里的url的那些信息的builder
        var builder = oldRequest
            .url()
            .newBuilder()

        var newBuilder = builder.port(0)

//        //得到新的url（已经追加好了参数）
//        var newUrl = builder.addQueryParameter("deviceId", "12345")
//                .addQueryParameter("token", "i_am_token")
//                .addQueryParameter("appVersion", "1.0.0-beta")
//                .build()

        //利用新的Url，构建新的request，并发送给服务器
        var newRequest = oldRequest
            .newBuilder()
            .url(newBuilder.build())
            .build()

        return chain.proceed(newRequest)

    }
}